<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <script src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/pintuer.js"></script>
    <script src="${pageContext.request.contextPath}/js/my.js"></script>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/pintuer.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/admin.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/mask.css">
    <script src="${pageContext.request.contextPath}/js/quit.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/jquery-dialogbox/jquery.dialogbox-1.0.css">
    <script src="${pageContext.request.contextPath}/jquery-dialogbox/jquery.dialogbox-1.0.js"></script>
    <style type="text/css">
        /*上传框样式*/
        .uploader { position:relative; display:inline-block; overflow:hidden; cursor:default; padding:0;
            margin:10px 0px; -moz-box-shadow:0px 0px 5px #ddd; -webkit-box-shadow:0px 0px 5px #ddd;
            box-shadow:0px 0px 5px #ddd; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; }
        .filename { float:left; display:inline-block; outline:0 none; height:32px; width:180px; margin:0; padding:8px 10px; overflow:hidden; cursor:default; border:1px solid; border-right:0; font:9pt/100% Arial, Helvetica, sans-serif; color:#777; text-shadow:1px 1px 0px #fff; text-overflow:ellipsis; white-space:nowrap; -moz-border-radius:5px 0px 0px 5px; -webkit-border-radius:5px 0px 0px 5px; border-radius:5px 0px 0px 5px; background:#f5f5f5; background:-moz-linear-gradient(top, #fafafa 0%, #eee 100%); background:-webkit-gradient(linear, left top, left bottom, color-stop(0%, #fafafa), color-stop(100%, #f5f5f5)); filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fafafa', endColorstr='#f5f5f5', GradientType=0);
            border-color:#ccc; -moz-box-shadow:0px 0px 1px #fff inset; -webkit-box-shadow:0px 0px 1px #fff inset; box-shadow:0px 0px 1px #fff inset; -moz-box-sizing:border-box; -webkit-box-sizing:border-box; box-sizing:border-box; }
        .button1 { float:left; height:32px; display:inline-block; outline:0 none; padding:8px 12px; margin:0; cursor:pointer; border:1px solid; font:bold 9pt/100% Arial, Helvetica, sans-serif; -moz-border-radius:0px 5px 5px 0px; -webkit-border-radius:0px 5px 5px 0px; border-radius:0px 5px 5px 0px; -moz-box-shadow:0px 0px 1px #fff inset; -webkit-box-shadow:0px 0px 1px #fff inset; box-shadow:0px 0px 1px #fff inset; }
        .uploader input[type=file] { position:absolute; top:0; right:0; bottom:0; border:0; padding:0; margin:0;
            height:30px; cursor:pointer; filter:alpha(opacity=0); -moz-opacity:0; -khtml-opacity: 0; opacity:0; }
        .w300{width: 300px;float:left;}
        .w150{width: 150px;float:left;}
        .form-x .form-group .label {width: 170px;}
        .form-x .form-group .field {width: calc(100% - 170px);}
    </style>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head">
        <strong class="icon-reorder"> 电子印章制作系统--申请信息录入</strong>
    </div>
    <div class="padding border-bottom form-x" >
        <ul class="search" style="padding-left:10px;">
            <li><a class="button border-main icon-plus-square-o" href="javaScript:window.location.href = document.referrer;"> 返回</a></li>
        </ul>
    </div>
    <form method="post" class="form-x" id="applyInfo_from" enctype="multipart/form-data">
        <div class="body-content">
            <ul class="search" >
                <li class="form-group">
                    <div class="label">
                        <label>印章类型：</label>
                    </div>
                    <div class="field">
                        <select id="sealTypeId" name="sealTypeId" style="width:150px; line-height:17px;display:inline-block">
                            <c:forEach items="${sealTypes}" var="item"  varStatus="status">
                                <option value="${item.sealTypeId}">${item.sealTypeName}</option>
                            </c:forEach>
                        </select>
                    </div>
                </li>
            </ul>
            <ul class="search" >
                <%--申请信息类别--%>
                <input type="hidden" id="applyType" name="applyType" value="${applyType}"/>
                <%--单位id--%>
                <input type="hidden" id="unitId" name="unitId" value="${unit.unitId}"/>
                <li class="form-group">
                    <div class="label">
                        <label>印章名称：</label>
                    </div>
                    <div class="field">
                        <input type="text" class="input w300" id="sealName" name="sealName" value="" />
                    </div>
                </li>
            </ul>
            <ul class="search" >
                <li class="form-group">
                    <div class="label">
                        <label>经办人姓名：</label>
                    </div>
                    <div class="field">
                        <input type="text"  class="input w300" id="jbr_name" name="jbr_name" value="" />
                    </div>
                </li>
                <li class="form-group">
                    <div class="label">
                        <label>经办人身份证号码：</label>
                    </div>
                    <div class="field">
                        <input type="text"  class="input w300" id="jbr_card_data" name="jbr_card_data" value=""/>
                        <input type="hidden"  id="jbr_card_type" name="jbr_card_type" value="111" />
                    </div>
                </li>
                <li class="form-group">
                    <div class="label">
                        <label>统一社会信用代码：</label>
                    </div>
                    <div class="field">
                        <input type="text"  class="input w300" value="${unit.credit_code}"/>
                    </div>
                </li>
                <%--readonly="readonly"--%>
                <li class="form-group">
                    <div class="label">
                        <label>使用单位行政区划代码：</label>
                    </div>
                    <div class="field">
                        <input type="text"  class="input w300"  value="${unit.area_number}" />
                    </div>
                </li>
            </ul>
            <ul class="search" >
                <li class="form-group">
                    <div class="label">
                        <label>审核材料：</label>
                    </div>
                    <div class="field">
                        <div class="uploader white">
                            <input type="text" id="fileName" value="审核材料（压缩包或PDF）" class="filename input w300" readonly/>
                            <input type="button" class="button1" value="上传文件"/>
                            <input type="file" id="attachmentFile"  name="attachmentFile" size="30"/>
                        </div>
                    </div>
                </li>
            </ul>
            <ul class="search" >
                <li class="form-group">
                    <div class="label">
                        <label></label>
                    </div>
                    <div class="field">
                        <button type="button" class="button bg-main icon-check-square-o w150" onclick="sealInfoSubmit()"> 提交申请</button>
                    </div>
                </li>
            </ul>
        </div>
    </form>
</div>
</body>
<script>
    /**
     *提交制作申请信息
     */
    function sealInfoSubmit() {
        const formData = new FormData($("#applyInfo_from")[0]);
        const vResult  = verification();
        if("true" ===vResult){
            //页面检查信息无误后
            $.ajax({
                type: "post",
                url: "${pageContext.request.contextPath}/apply/add_do.html",
                data: formData,
                cache: false,
                processData: false,
                contentType: false,
                success: function (data) {

                    const obj = eval('('+ data +')');
                    if(obj.message == "success"){
                        $('body').dialogbox({
                            type:"normal",title:"申请成功",
                            buttons:[{
                                Text:"确认",
                                ClickToClose:true,
                                callback:function (dialog){
                                    window.location.href = document.referrer;
                                }
                            }],
                            message:'已根据您提交的信息成功提交印章申请，请您等候审核制作！'
                        });
                    }else{
                        $('body').dialogbox({
                            type:"normal",title:"申请失败",
                            buttons:[{
                                Text:"确认",
                                ClickToClose:true,
                                callback:function (dialog){
                                    window.location.href = document.referrer;
                                }
                            }],
                            message:'申请提交失败，请您重试！'
                        });
                    }
                }
            });
        }else{
            $('body').dialogbox({
                type:"normal",title:"信息缺失",
                buttons:[{
                    Text:"确认",
                    ClickToClose:true,
                    callback:function (dialog){
                    }
                }],
                message:verificResult
            });
        }
    }



    function verification(){
        if(isNull($("#sealName").val())){
            return "印章名称不可为空！";
        }
        if(isNull($("#jbr_name").val())){
            return "印章名称不可为空！";
        }
        //验证身份证号
        //身份证号码
        const idcard =$("#jbr_card_data").val();
        if(!idcard){
            return "请输入有效合法的身份证号码！";
        }
        if(idcard.length<18){
            return "请输入有效合法的身份证号码！";
        }
        let len = 17;
        let sum = 0;
        let yzArray = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
        let codeArray = ['1','0','X','9','8','7','6','5','4','3','2'];
        for(let i=0;i<len;i++){
            sum+=idcard[i]*yzArray[i];
        }
        let mod = sum%11;
        if( codeArray[mod]==idcard[17] ){
            return "true";
        }
        return "true";
    }

    //上传图片 转换base64 显示。
    $("#attachment").change(function(){
        var fl=this.files.length;
        for(var i=0;i<fl;i++){
            var file = this.files[i];
            //上传文件格式
            var FileType = file.name.toLowerCase().split('.').splice(-1);
            var FileSize = file.size/1024 + 'kb';
            $("#fileName").val(file.name);
            if("rar" == FileType ||"zip" == FileType ||"word" == FileType ||"pdf" == FileType){
                var reader = new FileReader();
                reader.readAsDataURL(file);
                reader.onload = function(e){

                };
            }else{
                var fileTemp = $("#attachment");
                fileTemp.after(fileTemp.clone().val(""));
                fileTemp.remove();
                $("#fileName").val("审核材料（压缩包或PDF）");
                $('body').dialogbox({
                    type:"normal",title:"错误！",
                    buttons:[{
                        Text:"确认",
                        ClickToClose:true,
                        callback:function (dialog){
                            // window.history.go(-1)
                        }
                    }],
                    message:"附件只支持gif,jpg,pdf,png等格式！"
                });
            }
        }
    });

    function check(){
        //身份证号码
        const idcard =$("#jbr_card_data").val();
        if(!idcard){
            alert("请输入有效合法的身份证号码！");
            return false;
        }
        if(idcard.length<18){
            alert("请输入有效合法的身份证号码！");
            return false;
        }
        let len = 17;
        let sum = 0;
        let yzArray = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
        let codeArray = ['1','0','X','9','8','7','6','5','4','3','2'];
        for(let i=0;i<len;i++){
            sum+=idcard[i]*yzArray[i];
        }
        let mod = sum%11;
        if( codeArray[mod]==idcard[17] ){
            alert("有效合法的身份证号码！");
            return true;
        }
        return false;
    }

</script>
</html>